#include "Period.h"
#include <time.h>

CPeriod::CPeriod()
{
	m_nIndex = 0;
	time(&m_timeStamp);
	m_nCurrentStep = 0;
}

CPeriod::CPeriod(int nIndex, int nTotalSteps)
{
	m_nIndex = nIndex;
	time(&m_timeStamp);
	m_nCurrentStep = 0;
	m_nTotalSteps = nTotalSteps;
}

CPeriod::~CPeriod()
{
	::DeleteCriticalSection(&m_cs);
}

int CPeriod::Release()
{
	lock();
	m_nRef--;
	if (m_nRef == 0) {
		unlock();
		delete this;

		return 0;
	}
	else {
		unlock();
	}

	return m_nRef;
}

int CPeriod::getIndex()
{
	return m_nIndex;
}

__int64 CPeriod::getTimestamp()
{
	return m_timeStamp;
}

std::string & CPeriod::getSN()
{
	return m_strSN;
}

void CPeriod::setSN(const char *pszSN)
{
	m_strSN = pszSN;
}

int CPeriod::getTotalSteps()
{
	return m_nTotalSteps;
}

int CPeriod::getCurrentStep()
{
	return m_nCurrentStep;
}

CIntent * CPeriod::getIntent()
{
	return m_pIntent;
}

void CPeriod::nextStep()
{
	m_nCurrentStep += 10;
}

void CPeriod::SetStep(int nStep)
{
	m_nCurrentStep = nStep;
}